home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 020 / arcsourc.arc / ARCLST.MAC < prev    next >
Encoding:
Text File  |  1985-11-12  |  5.5 KB  |  170 lines

  1. /*  ARC - Archive utility - ARCLST
  2.  
  3. $define(tag,$$segment(@1,$$index(@1,=)+1))#
  4. $define(version,Version $tag(
  5. TED_VERSION DB =2.29), created on $tag(
  6. TED_DATE DB =11/12/85) at $tag(
  7. TED_TIME DB =11:21:46))#
  8. $undefine(tag)#
  9.     $version
  10.  
  11. (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  12.  
  13.     By:  Thom Henderson
  14.  
  15.     Description:
  16.          This file contains the routines used to list the contents
  17.          of an archive.
  18.  
  19.     Language:
  20.          Computer Innovations Optimizing C86
  21. */
  22. #include <stdio.h>
  23. #include "arc.h"
  24.  
  25. lstarc(num,arg)                        /* list files in archive */
  26. int num;                               /* number of arguments */
  27. char *arg[];                           /* pointers to arguments */
  28. {
  29.     struct heads hdr;                  /* header data */
  30.     int list;                          /* true to list a file */
  31.     int did[$maxarg];                  /* true when argument was used */
  32.     long tnum, tlen, tsize;            /* totals */
  33.     int n;                             /* index */
  34.  
  35.     tnum = tlen = tsize = 0;           /* reset totals */
  36.  
  37.     for(n=0; n<num; n++)               /* for each argument */
  38.          did[n] = 0;                   /* reset usage flag */
  39.  
  40.     if(!kludge)
  41.     {    printf("Name          Length  ");
  42.          if(bose)
  43.               printf("  Stowage    SF   Size now");
  44.          printf("  Date     ");
  45.          if(bose)
  46.               printf("  Time    CRC");
  47.          printf("\n");
  48.  
  49.          printf("============  ========");
  50.          if(bose)
  51.               printf("  ========  ====  ========");
  52.          printf("  =========");
  53.          if(bose)
  54.               printf("  ======  ====");
  55.          printf("\n");
  56.     }
  57.  
  58.     openarc(0);                        /* open archive for reading */
  59.  
  60.     if(num)                            /* if files were named */
  61.     {    while(readhdr(&hdr,arc))      /* process all archive files */
  62.          {    list = 0;                /* reset list flag */
  63.               for(n=0; n<num; n++)     /* for each template given */
  64.               {    if(match(hdr.name,arg[n]))
  65.                    {    list = 1;      /* turn on list flag */
  66.                         did[n] = 1;    /* turn on usage flag */
  67.                         break;         /* stop looking */
  68.                    }
  69.               }
  70.  
  71.               if(list)                 /* if this file is wanted */
  72.               {    if(!kludge)
  73.                         lstfile(&hdr); /* then tell about it */
  74.                    tnum++;             /* update totals */
  75.                    tlen += hdr.length;
  76.                    tsize += hdr.size;
  77.               }
  78.  
  79.               fseek(arc,hdr.size,1);   /* move to next header */
  80.          }
  81.     }
  82.  
  83.     else while(readhdr(&hdr,arc))      /* else report on all files */
  84.     {    if(!kludge)
  85.               lstfile(&hdr);
  86.          tnum++;                       /* update totals */
  87.          tlen += hdr.length;
  88.          tsize += hdr.size;
  89.          fseek(arc,hdr.size,1);        /* skip to next header */
  90.     }
  91.  
  92.     closearc(0);                       /* close archive after reading */
  93.  
  94.     if(!kludge)
  95.     {    printf("        ====  ========");
  96.          if(bose)
  97.               printf("            ====  ========");
  98.          printf("\n");
  99.     }
  100.  
  101.     printf("Total %6ld  %8ld  ",tnum,tlen);
  102.     if(bose)
  103.          printf("          %3ld%%  %8ld  ",100L - (100L*tsize)/tlen,tsize);
  104.     printf("\n");
  105.  
  106.     if(note)
  107.          for(n=0; n<num; n++)          /* report unused args */
  108.               if(!did[n])
  109.                    printf("File not found: %s\n",arg[n]);
  110. }
  111.  
  112. static lstfile(hdr)                    /* tell about a file */
  113. struct heads *hdr;                     /* pointer to header data */
  114. {
  115.     int yr, mo, dy;                    /* parts of a date */
  116.     int hh, mm, ss;                    /* parts of a time */
  117.  
  118.     static char *mon[] =               /* month abbreviations */
  119.     {    "Jan",    "Feb",    "Mar",    "Apr",
  120.          "May",    "Jun",    "Jul",    "Aug",
  121.          "Sep",    "Oct",    "Nov",    "Dec"
  122.     };
  123.  
  124.     yr = (hdr->date >> 9) & 0x7f;      /* dissect the date */
  125.     mo = (hdr->date >> 5) & 0x0f;
  126.     dy = hdr->date & 0x1f;
  127.  
  128.     hh = (hdr->time >> 11) & 0x1f;     /* dissect the time */
  129.     mm = (hdr->time >> 5) & 0x3f;
  130.     ss = (hdr->time & 0x1f) * 2;
  131.  
  132.     printf("%-12s  %8ld  ",hdr->name,hdr->length);
  133.  
  134.     if(bose)
  135.     {    switch(hdrver)
  136.          {
  137.          case 1:
  138.          case 2:
  139.               printf("   --   ");
  140.               break;
  141.          case 3:
  142.               printf(" Packed ");
  143.               break;
  144.          case 4:
  145.               printf("Squeezed");
  146.               break;
  147.          case 5:
  148.               printf("crunched");
  149.               break;
  150.          case 6:
  151.               printf("Crunched");
  152.               break;
  153.          default:
  154.               printf("Unknown!");
  155.          }
  156.  
  157.          printf("  %3d%%",100L - (100L*hdr->size)/hdr->length);
  158.          printf("  %8ld  ",hdr->size);
  159.     }
  160.  
  161.     printf("%2d %3s %02d", dy, mon[mo-1], (yr+80)%100);
  162.  
  163.     if(bose)
  164.          printf("  %2d:%02d%c  %04x",
  165.               (hh>12?hh-12:hh), mm, (hh>12?'p':'a'),
  166.               hdr->crc);
  167.  
  168.     printf("\n");
  169. }
  170.